package cn.yxr.controller;

import cn.yxr.pojo.AppCategory;
import cn.yxr.pojo.AppInfo;
import cn.yxr.pojo.AppVersion;
import cn.yxr.pojo.DataDictionary;
import cn.yxr.service.AppCategoryService;
import cn.yxr.service.AppVersionService;
import cn.yxr.service.AppinfoService;
import cn.yxr.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/back_App")
public class AppCheckController {
    @Autowired
    private AppinfoService appInfoService;
    @Autowired
    private DataDictionaryService dataDictionaryService;
    @Autowired
    private AppCategoryService appCategoryService;
    @Autowired
    private AppVersionService appVersionService;
    // 跳转页面
    @RequestMapping("/to_app_List")
    public String to_app_List(){
        return "applist";
    }
    // 查询页面    查询所有数据
    @RequestMapping("/search_AppInfo")
    @ResponseBody
    public List<AppInfo> search_AppInfo(AppInfo appInfo){
        appInfo.setStatus(1);
        List<AppInfo> appInfos = appInfoService.search_AppInfoList(appInfo);
        return appInfos;
    }

    // 查询平台
    @RequestMapping("/serachFlatName")
    @ResponseBody
    public List<DataDictionary> serachFlatName(DataDictionary dataDictionary){
        dataDictionary.setTypeCode("APP_FLATFORM");
        List<DataDictionary> list = dataDictionaryService.serachDictionary(dataDictionary);
        return list;
    }
    // 查询分类
    @RequestMapping("/serachType")
    @ResponseBody
    public List<AppCategory> serachType(Integer parentId){
        AppCategory appCategory=new AppCategory();
        appCategory.setParentId(parentId);
        List<AppCategory> list = appCategoryService.serachTypeList(appCategory);

        return list;
    }
    // 跳转审核页面
    @RequestMapping("/to_Update_Status/{id}")
    public String to_Update_Status(@PathVariable("id") Integer id, Model model){
        AppInfo appInfo=new AppInfo();
        appInfo.setId(id);
        System.err.println("1");
        List<AppInfo> appInfolsit = appInfoService.search_AppInfoList(appInfo);
        AppVersion appVersion=new AppVersion();
        for (AppInfo appInfo2 : appInfolsit) {
            // 查询版本
            appVersion.setAppId(appInfo2.getId());
            List<AppVersion> listve = appVersionService.search_Version(appVersion);
            for (AppVersion appVersion2 : listve) {
                model.addAttribute("appVersion", appVersion2);
            }
            model.addAttribute("appInfo", appInfo2);
        }
        return "appcheck";
    }
    // 修改审核状态
    @RequestMapping("/update_StatusByid")
    public String update_Status(AppInfo appInfo){
        appInfo.setUpdateDate((java.sql.Date) new Date());
        appInfoService.update_StatusByid(appInfo);
        return "applist";
    }


}
